Uses crt,Routine,Process,DispProc;
const
	MaxNumberProcess = 20;
var
	{main}
	M:descptr;
	a: array[0..MaxNumberProcess] of body_process;
function isEscape:boolean;
var c:char;
begin
  if (keypressed) then
	begin
	   writeln('isEscape running, procedure 1');
	   c := readkey;
	   writeln(ord(c));
	   if (ord(c) = 0) then
		begin
		 c:=readkey;
		 if (c = chr(27)) then
		   begin
			isEscape :=true;
		   end
		else
		   begin
			isEscape :=false;
		   end;
		end
	    else
		begin
		   if(ord(c) = 27) then isEscape := true else
		   isEscape:=false;
		end;
	end
    else
	begin
	   isEscape:=false;
	end;
end;
Procedure body_i;
far;
begin
	while (true) do
		writeln('Hello, this is process:', get_current_dispatcher^.get_current_process^.get_id);
	
end;
Procedure body_last;
far;
begin
	while (true) do
		begin
			writeln('Hello, this is process:', get_current_dispatcher^.get_current_process^.get_id);
			writeln('For exit press <Esc>');
			if (isEscape) then
			 get_current_dispatcher^.stop;
		end;
end;
var 
	D:PDispatcherProcess;
	nProcess:byte;
	i:byte;
begin
	writeln(MemAvail);
	new(M);
	writeln('enter the number of process');
	readln(nProcess);
	for i:=1 to nProcess do a[i]:=body_last;
	D:=new(PDispatcherProcess, init(nProcess, a, M));
	set_current_dispatcher(D);
	D^.start;
	D^.done;
	dispose(M);
	writeln(MemAvail)
end.
